﻿using System;
using System.Collections;
using System.Collections.Generic;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Image = Unity.UIWidgets.widgets.Image;
using Transform = Unity.UIWidgets.widgets.Transform;

public class MyTestUIWidgets : UIWidgetsPanel
{
    protected override void OnEnable()
    {
        FontManager.instance.addFont(Resources.Load<Font>(path: "fonts/MaterialIcons-Regular"), "Material Icons");
        base.OnEnable();
    }

    protected override Widget createWidget()
    {
        //return new CounterApp();
        // return new NewRoute();
        return new TestApp();
    }

    class TestApp : StatelessWidget
    {
        Widget redBox=new DecoratedBox(
            decoration: new BoxDecoration(color: Colors.red)
        );
        
        public override Widget build(BuildContext context)
        {
            return new Text("123");
        }
    }

    //计数器app
    class CounterApp : StatelessWidget
    {
        public override Widget build(BuildContext context)
        {
            return new MaterialApp(
                title: "Flutter Demo",
                theme: new ThemeData(
                    primarySwatch: Colors.blue
                ),
                home: new MyHomePage(title: "Flutter Demo Home Page")
            );
        }
    }

    class MyHomePage : StatefulWidget
    {
        String title;

        public MyHomePage(string title) : base(key: null)
        {
            this.title = title;
        }

        public override State createState()
        {
            return new NumberState();
        }
    }

    class NumberState : State<MyHomePage>
    {
        private int number = 0;

        private void OnTap()
        {
            setState(() => number++);
        }

        public override Widget build(BuildContext context)
        {
            return new Transform(
                //alignment: Alignment.topRight, //相对于坐标系原点的对齐方式
                transform: Matrix3.makeScale(1f, 1f), //transform组件必须要有这一句
                child: new Scaffold(
                    appBar: new AppBar(
                        title: new Text("Main route")
                    ),
                    body: new Center(
                        child: new Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: new List<Widget>()
                            {
                                new Container(
                                    width: 200,
                                    height: 200,
                                    child: new GestureDetector(
                                        onTap: OnTap,
                                        child: new Center(
                                            child: new Text($"number: {number}",
                                                style: new TextStyle(fontSize: 20)
                                            )
                                        )
                                    ),
                                    decoration: new BoxDecoration(color: Colors.blue)
                                ),
                                new FlatButton(
                                    child: new Text("open new route"),
                                    textColor: Colors.blue,
                                    onPressed: () =>
                                    {
                                        //导航到新路由   
                                        Navigator.push(context,
                                            new MaterialPageRoute(builder: (c) => { return new NewRoute(); }));
                                    }),
                                new Transform(
                                    //alignment: Alignment.topRight, //相对于坐标系原点的对齐方式
                                    //transform: Matrix3.makeScale(0.1f,0.1f),
                                    transform: Matrix3.makeScale(1f, 1f),
                                    child: new Container(
                                        padding: EdgeInsets.all(8.0f),
                                        color: Colors.deepOrange,
                                        child: new Text("Apartment for rent!")
                                    )
                                ),
                                new Text("Hello word",
                                    textScaleFactor: 1),
                                Text.rich(
                                    new TextSpan(
                                        children: new List<TextSpan>()
                                        {
                                            new TextSpan(text: "Hello"),
                                            new TextSpan(text: "www.baidu.com",
                                                style: new TextStyle(
                                                    color: Colors.blue
                                                ),
                                                recognizer: new TapGestureRecognizer() {onTap = () => print("ontap")})
                                        })
                                ),
                                new RaisedButton(
                                    child: new Text("RaisedButton"),
                                    onPressed: () => print("RaisedButton")
                                ),
                                new FlatButton(
                                    color: Colors.blue,
                                    highlightColor: Colors.blue[700],
                                    colorBrightness: Brightness.dark,
                                    splashColor: Colors.grey,
                                    child: new Text("FlatButton"),
                                    shape: new RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0f)),
                                    onPressed: () => print("FlatButton")
                                ),
                                new OutlineButton(
                                    child: new Text("OutlineButton"),
                                    onPressed: () => print("OutlineButton")
                                )
                            }
                        )
                    )
                )
            );
        }
    }

    class NewRoute : StatelessWidget
    {
        public override Widget build(BuildContext context)
        {
            return new Scaffold(
                appBar: new AppBar(
                    title: new Text("New route")
                ),
                body: new Center(
                    child: new Text("This is new route")
                )
            );
        }
    }
}